package com.lktx.sso.service;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.oauth2.SaOAuth2Manager;
import cn.dev33.satoken.oauth2.template.SaOAuth2Util;
import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.ioc.annotation.Bean;
import com.lktx.sso.admin.entity.SsoApp;
import com.lktx.sso.admin.entity.SsoUser;
import com.lktx.sso.admin.service.SsoAppService;
import com.lktx.sso.admin.service.SsoUserService;
import com.lktx.sso.admin.vo.SsoUserApp;

import java.util.List;

@Bean
public class OpenApiService {

    @Autowired
    private SsoAppService ssoAppService;

    @Autowired
    private SsoUserService ssoUserService;

    public SsoUserApp appCenter(){
        try {
            String accessToken = SaOAuth2Manager.getDataResolver().readAccessToken(SaHolder.getRequest());
            Object loginId = SaOAuth2Util.getLoginIdByAccessToken(accessToken);
            return ssoUserService.login(loginId.toString());
        }catch (Exception e){
            return null;
        }
    }

}
